package Classes.GameUtils
{
	import Classes.GameDatas.GD_Player;
	import Classes.GameViews.ViewIcons.ViewIcon;
	import Classes.GameViews.ViewPanels.VP_Main;
	import Classes.GameViews.ViewPanels.VP_beathartWindon;
	import Classes.Managers.M_Communication;
	import Classes.Managers.M_ConfigData;
	import Classes.staticinfo.Language;
	
	import UIComponents.FlatInfo;
	import UIComponents.IUseItem;
	
	import flash.display.DisplayObject;
	import flash.system.ApplicationDomain;

	/** 
	 * @author thy
	 * @version 1.0.0 
	 * 创建时间：Jun 6, 2012 5:45:16 PM 
	 */ 
	public class GU_dealSharePreWin
	{
		private static var _instance:GU_dealSharePreWin;
		public function GU_dealSharePreWin()
		{
		}
		
		public static function get instance():GU_dealSharePreWin
		{
			if(!_instance)_instance=new GU_dealSharePreWin();
			return _instance;
		}
		
		/**
		 * 发送分享成功的命令 
		 */		
		public function sendShareCommand():void
		{
//			if(!VP_Main.instance.interfaceUI["isFullScreen"])
//			{
//				M_ConfigData.instance.changeParams("window");
//			}
			M_Communication.instance.send(125000);
		}
		
		public function haldSharePreFun(command:int):void
		{
			var dis:DisplayObject;
			var shareObj:Object=new Object();
			var type:int=-1
			
			switch(command)
			{
				case 12304://兑换、合成
					dis=new (ApplicationDomain.currentDomain.getDefinition("dhcg_new") as Class);
					shareObj=this.joinObj(dis,Language.exchangSuccess,Language.exchangTitle,Language.exchangBtn);
					type=1;
					break;
				case 127002://雇佣好友
					dis=new (ApplicationDomain.currentDomain.getDefinition("gycg_new") as Class);
					shareObj=this.joinObj(dis,Language.hireSuccessNew,Language.hireTitleNew,Language.hireBtn);
					type=2;
					break;
				case 12307://建设升级
					dis=new (ApplicationDomain.currentDomain.getDefinition("jscg_new") as Class);
					shareObj=this.joinObj(dis,Language.buildSuccessNew,Language.buildTitleNew,Language.buildBtnNew);
					type=3;
					break;
				case 12306://矿建成功
					dis=new (ApplicationDomain.currentDomain.getDefinition("kccg_new") as Class);
					shareObj=this.joinObj(dis,Language.kcSuccessNew,Language.kcTitleNew,Language.buildBtnNew);
					type=4;
					break;
				case 12200://任务完成
					dis=new (ApplicationDomain.currentDomain.getDefinition("rwwc_new") as Class);
					shareObj=this.joinObj(dis,Language.missSuccessNew,Language.missTitleNew,Language.missBtnNew);
					type=9;
					break;
				case 1111://友情行动力为0
					dis=new (ApplicationDomain.currentDomain.getDefinition("zjhy_new") as Class);
					shareObj=this.joinObj(dis,Language.helpSuccessNew,Language.helpTitleNew,Language.helpBtnNew);
					type=11;
					break;
			}
			if(type==-1)return;
			(new VP_beathartWindon()).setWinInfo(shareObj,type,false,false);
			type=-1;
		}
		
		public function playUpNewThings(msgObj:Object):void
		{
			//玩家升级(需要后台返回升级需要的物品)
			var dis:DisplayObject=new (ApplicationDomain.currentDomain.getDefinition("sj_new") as Class);
			var items:Array=String(msgObj.value).split(",");
			var shareObj:Object=this.joinObj(dis,Language.upSuccessNew,Language.upTitleNew,Language.upBtnNew,items,false);
			(new VP_beathartWindon()).setWinInfo(shareObj,7,true,true);
		}
		
		public function joinObj(windonIconTitle:DisplayObject=null,windonContext:String="",rewardTxt:String="",CenterBtnTxt:String="",items:Array=null,isOnlyJb:Boolean=true):Object
		{
			//数据源 windonIconTitle,windonContext,rewardTxt,CenterBtnTxt,items[num,lock,pic]
			var obj:Object=new Object();
			obj.windonIconTitle=windonIconTitle;
			obj.windonContext=windonContext;
			obj.rewardTxt=rewardTxt;
			obj.CenterBtnTxt=CenterBtnTxt;
			var _items:Array=new Array();
			if(isOnlyJb)
			{
				var o:Object=new Object();
				var vi:DisplayObject=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_JB"});
				o.num=10;
				o.lock=false;
				o.pic=vi;
				o.discript=Language.jb;
				_items.push(o);
			}else{
				//处理除了金币以外的事情  1-2,2(rewardItemID)-3(itemNum) 顺序是：普通  粉丝  黄钻
				for(var i:int=0;i<items.length;i++)
				{
					var ti:Array=String(items[i]).split("-");
					var oo:Object=new Object();
					var vc:DisplayObject=this.getSpectialIcon(ti[0]);
					vc.width=75;
					vc.height=75;
					oo.num=ti[1];
					if(i==1)
					{
						if(FlatInfo.isFensi)
						{
							oo.lock=false;
						}else{
							oo.lock=true;
						}
					}
					
					if(i==2)
					{
						if(GD_Player.instance.qqVipId==0)
						{
							oo.lock=true;
						}else{
							oo.lock=false;
						}
					}
					oo.pic=vc;
					oo.discript=vc["displayViewIconName"];
					_items.push(oo);
				}
			}
			obj.items=_items;
			return obj;
		}
		
		private function getSpectialIcon(id:Number=0,w:int=75,h:int=75):DisplayObject
		{
			if(id==5)
			{
				var dis:DisplayObject=new (ApplicationDomain.currentDomain.getDefinition("maxAction") as Class);
				dis["displayViewIconName"]=Language.maxAct;
				return dis;
			}
			
			var countPic:ViewIcon=null
			switch(id)
			{
				case 1://金币
					countPic=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_JB"});
					countPic.displayViewIconName=Language.jb;
					break;
				case 3:
					countPic=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_Act"});
					countPic.displayViewIconName=Language.act;
					break;
				case 4:
					countPic=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_Exp"});
					countPic.displayViewIconName=Language.exp;
					break;
				case 10:
					countPic=ViewIcon.creat({sourceName:"icon0.swf",picName:"Icon_OB"});
					countPic.displayViewIconName=Language.ob;
					break;
				default :
					var iuserItem:IUseItem=GD_deal.instance.getDataById(id);
					var vi:ViewIcon=(iuserItem.itemPic) as ViewIcon;
					countPic=ViewIcon.creat({sourceName:vi.sourceName,picName:vi.picName});
					countPic.displayViewIconName=iuserItem.itemName+"："+iuserItem.description;
					break;
			}
			countPic.iHeight=w;
			countPic.iWidth=h;
			countPic.setNumSpVisiable(false);
			return countPic;
		}
		
	}
}
